package com.zeng.jiudian.servlet;

import com.alibaba.fastjson.JSONObject;
import redis.clients.jedis.Jedis;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author JJ_yo
 * @Date 2020/7/21 - 14:53
 */
@WebServlet("/manage")
public class ManageServlet extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=utf-8");

        Jedis jedis = new Jedis();
        jedis.select(1);
        String username = jedis.get(req.getParameter("loginUsername"));

        JSONObject jsonObject = new JSONObject();
        if (username != null && !"".equals(username))
        {
            jsonObject.put("username", username);
        }
        else
        {
            jsonObject.put("username", null);
        }
        resp.getWriter().println(jsonObject);
    }
}
